package com.yonyou.iuap.shell.service.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.util.StringUtils;

import com.yonyou.iuap.pub.DateUtil;
import com.yonyou.iuap.pub.IDFactory;
import com.yonyou.iuap.shell.dao.KmAttachmentEntityDao;
import com.yonyou.iuap.shell.entity.KmAttachmentEntity;
import com.yonyou.iuap.shell.pub.IShellDaoEnum;
import com.yonyou.iuap.shell.pub.ResultDto;
import com.yonyou.iuap.shell.service.intf.IKmAttachmentService;

public class KmAttachmentServiceImpl implements IKmAttachmentService {
	@Autowired
	@Qualifier(IShellDaoEnum.Shell_Dao_KmAttachmentEntityDao)
	private KmAttachmentEntityDao kmAttachmentEntityDao;

	public ResultDto insert(List<KmAttachmentEntity> listvo) {
		ResultDto rsDto = new ResultDto();
		rsDto.setStatus(0);
		rsDto.setMessage("添加完成!");
		if(listvo!=null && listvo.size()>0){
			for(KmAttachmentEntity vo : listvo){
				vo.setPk_attachment(IDFactory.getInstance().getID());
				vo.setDr(0);
				vo.setPk_creator(vo.getPk_uploaduser());
				vo.setTs(DateUtil.formatDateTime(new Date()));
				vo.setDtcreate(new Date());
				int i_insert = kmAttachmentEntityDao.insertSelective(vo);
			}
		}
		return rsDto;
	}

	public ResultDto update(List<KmAttachmentEntity> listvo) {
		ResultDto rsDto = new ResultDto();
		rsDto.setStatus(0);
		rsDto.setMessage("更新完成!");
		if(listvo!=null && listvo.size()>0){
			for(KmAttachmentEntity vo : listvo){
				int i_up = kmAttachmentEntityDao.updateByPrimaryKeySelective(vo);
			}
		}
		return rsDto;
	}

	public ResultDto deleteByCondition(String whereSql) {
		ResultDto rsDto = new ResultDto();
		if(StringUtils.isEmpty(whereSql)){
			rsDto.setStatus(1);
			rsDto.setMessage("删除条件不能为空!");
		}else{
			int i_del = kmAttachmentEntityDao.deleteByCondition(whereSql);
			rsDto.setStatus(0);
			rsDto.setMessage("删除完成!");
		}
		return rsDto;
	}

	public ResultDto queryByCondition(String whereSql) {
		ResultDto rsDto = new ResultDto();
		List<KmAttachmentEntity> listvo = kmAttachmentEntityDao.selectByCondition(whereSql);
		rsDto.setStatus(0);
		rsDto.setMessage("数据查询成功!");
		rsDto.setNum(listvo==null?0:listvo.size());
		rsDto.setCount(listvo==null?0:listvo.size());
		rsDto.setData(listvo);
		return rsDto;
	}
	
	
}
